package com.guet;
import javax.imageio.ImageIO;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.*;
import java.util.List;

public class MyJFrame{
    static MyShapesPanel drawPanel;
    public MyJFrame(){
        drawPanel=new MyShapesPanel(); //呈现画板地图
        new MyGraphics(drawPanel);
    }
}
//实现画板的类
class MyShapesPanel extends JPanel implements Runnable{
    public algorithm alg=new algorithm();
    public MGraph mgraph=alg.mGraph;
    public JTextArea messageText;  //储存导航界面的信息文本域
    public final List<Integer> shortest=new LinkedList<>();
    public final Map<Integer,vexsinfo> showPoints=new HashMap<>();
    int run=0;int id;int x;int y,speedUp=1,every=1; //run是否运行，id，xy运行到的位置，speedUp速运行度,every用在标签中显示-->速度/every秒
    int showAll=0;
    String currentTime="当前时间";
    String goWay="步行";
    public MyShapesPanel(){
        setBackground(Color.white);
    }
    public void paintComponent(Graphics g){
        super.paintComponent(g);
        File file=new File("resources/guet.jpg");
        BufferedImage bufImg;
        try{
            bufImg= ImageIO.read(file);
        }catch (IOException e){
            System.out.println("图片加载出错");
            return;
        }
        g.drawImage(bufImg,0,0,750,650,200,0,900,650,null);
        //各个结点的标点
        g.setColor(Color.red);
        for(vexsinfo v:showPoints.values()){
            g.setFont(new Font("黑体",Font.CENTER_BASELINE,10));
            g.setColor(new Color(196, 107, 47));
            g.fillOval(v.logicx,v.logicy,10,10);
            g.setColor(Color.black);
            g.drawLine(v.logicx+5,v.logicy-3,v.logicx+20, v.logicy-20);
            g.drawString(v.name,v.logicx+15,v.logicy-20);
            g.setColor(Color.BLUE);
        }
        if(showAll==1){
            for(vexsinfo v:mgraph.vexs.values()){
                int a[]={v.top,v.bottom,v.left,v.right};
                System.out.println(v.name);
                for(int j=0;j<4;j++){
                    if(a[j]==-1)continue;
                    ((Graphics2D) g).setStroke(new BasicStroke(1.0f));
                    g.setColor(Color.BLUE);
                    vexsinfo v1=mgraph.vexs.get(a[j]);
                    g.drawLine(v1.logicx+3,v1.logicy+3,v.logicx+3,v.logicy+3);
                    int midX=(v1.logicx+v.logicx)/2;
                    int midY=(v1.logicy+v.logicy)/2;
                    g.setFont(new Font("黑体",Font.BOLD,8));
                    g.setColor(Color.red);
                    if(mgraph.arcs[v1.id][v.id]!=0)g.drawString(mgraph.arcs[v1.id][v.id]+"",midX-5,midY);
                }
            }
        }
        if(shortest.size()!=0) {
            Iterator it = shortest.iterator();
            int start = 0;
            while (it.hasNext()) {
                int end = (int) it.next();
                if (start == 0) {
                    start = end;
                    continue;
                }
                ((Graphics2D) g).setStroke(new BasicStroke(3.0f));
                g.setColor(Color.BLUE);
                vexsinfo v1 = mgraph.vexs.get(start);
                vexsinfo v2 = mgraph.vexs.get(end);
                g.drawLine(v1.logicx + 3, v1.logicy + 3, v2.logicx + 3, v2.logicy + 3);
                int midX = (v1.logicx + v2.logicx) / 2;
                int midY = (v1.logicy + v2.logicy) / 2;
                g.setFont(new Font("黑体", Font.BOLD, 8));
                g.setColor(Color.red);
                if (mgraph.arcs[v1.id][v2.id] != 0) g.drawString(mgraph.arcs[v1.id][v2.id] + "", midX - 5, midY);
                start = end;
            }
        }
        if(run==1){
            vexsinfo v=mgraph.vexs.get(id);
            ((Graphics2D) g).setStroke(new BasicStroke(3.0f));
            g.setColor(Color.BLUE);
            g.drawLine(v.logicx+3,v.logicy+3,x+3,y+3);
            g.setColor(Color.black);
            g.fillOval(x,y,8,8);
        }
    }
    public void towPointDrawLine(List<Integer> ids){
        shortest.clear();
        showPoints.get(mgraph.vexs.get(ids.get(0)));
        showPoints.get(mgraph.vexs.get(ids.get(ids.size()-1)));
        shortest.addAll(ids);
        repaint();
    }
    @Override
    public void run() {
        run=1;
        int Distance=alg.getListIdsDistance(shortest); //总路线长度
        int allTime=0;
        int currentP=shortest.size()-1;
        int vexSid=shortest.get(currentP--);
        int vexPid=shortest.get(currentP--);
        int speed= (int)alg.getSpeed(goWay,currentTime,vexSid,vexPid);
        vexsinfo vexP= mgraph.vexs.get(vexPid);
        vexsinfo vexS= mgraph.vexs.get(vexSid);
        while(currentP>=-1){
            shortest.remove(currentP+2);
            double x=vexS.logicx;
            double y=vexS.logicy;
            double dx,dy;
            int t=mgraph.arcs[vexSid][vexPid]/speed;
            if(vexS.logicy<vexP.logicy){
                dy=(vexP.logicy-vexS.logicy)*1.0/t;
            }else dy=(vexS.logicy-vexP.logicy)*(-1.0)/t;
            if(vexS.logicx<vexP.logicx){
                dx=(vexP.logicx-vexS.logicx)*1.0/t;
            }else dx=(vexS.logicx-vexP.logicx)*(-1.0)/t;
            this.id=vexPid;
            int speedUpTemp=speedUp;
            int s=mgraph.arcs[vexSid][vexPid];
            for(int i=1;i<=t/speedUpTemp+1&&Distance>0;i++,allTime+=speedUpTemp){
                if(Distance-speed*speedUpTemp>0)Distance-=speed*speedUpTemp;
                if(x!=vexP.logicx)x+=dx*speedUpTemp;
                if(y!=vexP.logicy)y+=dy*speedUpTemp;
                this.x=(int)x;
                this.y=(int)y;
                messageText.setText("已用时:"+allTime+"s , 剩余路程:"+Distance+"m\n" +
                        "当前速度: "+speed*speedUpTemp+"m/"+every+"s\n" +
                        "你目前位于:"+vexS.name+"与"+vexP.name+"的路线上"+((vexP.croded_level==1.0F)?"":"(当前时刻拥挤路段)"));
                repaint();
                try {
                    Thread.sleep(1000/speedUpTemp);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                if(speedUpTemp!=speedUp){
                    s-=speedUpTemp*i*speed; //两节点剩余距离-=上次的速度下*上次速度下的用时i
                    speedUpTemp=speedUp;
                    t=s/speed;  //计算剩余路程大概多久到达下一个结点
                    i=0;  //i置为零，记录下次的当前速度下用时
                }
            }
            vexS=vexP;
            vexSid= vexS.id;
            if(currentP==-1){
                JOptionPane.showMessageDialog(null,"你已到达"+vexP.name);
                break;
            }
            vexP=mgraph.vexs.get(shortest.get(currentP--));
            vexPid=vexP.id;
        }
        run=0;
    }
}
class MyGraphics extends JFrame{
    public MyGraphics(MyShapesPanel drawPanel){
        getContentPane().add(drawPanel);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setLocation(100,50);
        setSize(760, 690);
        setTitle("校园导航系统");
        JMenuBar jmenubar=new JMenuBar();
        JMenu navigation=new JMenu("导航");
        jmenubar.add(navigation);
        JMenu introduce=new JMenu("地点介绍");
        jmenubar.add(introduce);
        JMenu root=new JMenu("管理员端");
        jmenubar.add(root);
        setJMenuBar(jmenubar);
        navigation.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                navigationJFrame nv=new navigationJFrame(getSonX());
            }
            private int getSonX() {
                return getX()+getWidth()-14;
            }
        });
        introduce.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                com.guet.introduceJFrame nv=new introduceJFrame(getsonX());
            }
            private int getsonX() {
                return getX()+getWidth()-14;
            }
        });
        root.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                new rootJFrame(getWidth()+getX());
            }
        });
        setVisible(true);
    }
}
class navigationJFrame extends JFrame{
    static String startName="";
    static String endName="";
    public void showStartAndEnd(){
        MyJFrame.drawPanel.showPoints.clear();
        if(!startName.equals("")){
            vexsinfo v=new fileUse().getVexByName(startName);
            MyJFrame.drawPanel.showPoints.put(v.id,v);
        }
        if(!endName.equals("")){
            vexsinfo v1=new fileUse().getVexByName(endName);
            MyJFrame.drawPanel.showPoints.put(v1.id,v1);
        }
        MyJFrame.drawPanel.repaint();
    }
    public navigationJFrame(int x){
        setLayout(null);
        setSize(600,700);
        setLocation(x,0);
        setTitle("导航页");
        JComboBox startCom=new JComboBox();
        JComboBox endCom=new JComboBox();
        JButton runStartBtn=new JButton("开始虚拟运动");
        JButton speedUpBtn=new JButton("开启虚拟加速");
        JTextArea messageText=new JTextArea("已用时:00:00 , 剩余路程:0m\n" +
                " 当前速度:0 m/s\n" +
                "你目前位于:0");
        messageText.setFont(new Font("黑体",Font.BOLD,25));
        JLabel distanceLabel=new JLabel("xxx -> yyy: 0 m");
        JLabel warnLabel=new JLabel("");
        distanceLabel.setFont(new Font("黑体",Font.BOLD,18));
        JButton startBtn=new JButton("查找");
        JButton endBtn=new JButton("查找");
        JLabel startLabel=new JLabel("起点:");
        JLabel endLabel=new JLabel("终点:");
        JLabel transportWayLabel=new JLabel("交通方式:");
        ButtonGroup buttonGroup=new ButtonGroup();
        JRadioButton walk=new JRadioButton("步行");
        JRadioButton cycling=new JRadioButton("骑行");
        JRadioButton driving=new JRadioButton("驾车");
        JLabel periodLabel=new JLabel("时间段");
        JComboBox periodCom=new JComboBox();
        JButton optimalBtn=new JButton("查找用时最短路线");
        JButton shortestBtn=new JButton("查找距离最短路线");
        startCom.setBounds(85,230,350,25);
        endCom.setBounds(85,300,350,25);
        startBtn.setBounds(465,230,60,25);
        endBtn.setBounds(465,300,60,25);
        startLabel.setBounds(25,230,50,25);
        endLabel.setBounds(25,300,60,25);
        transportWayLabel.setBounds(25,350,60,25);
        walk.setBounds(105,350,55,25);
        cycling.setBounds(205,350,55,25);
        driving.setBounds(305,350,55,25);
        periodLabel.setBounds(25,400,55,25);
        periodCom.setBounds(85,400,350,25);
        optimalBtn.setBounds(55,510,400,50);
        shortestBtn.setBounds(55,580,400,50);
        distanceLabel.setBounds(15,170,600,20);
        runStartBtn.setBounds(450,80,120,35);
        speedUpBtn.setBounds(450,120,120,35);
        messageText.setBounds(15,15,400,150);
        warnLabel.setBounds(12,190,400,35);
        messageText.setLineWrap(true);
        messageText.setEditable(false);
        messageText.setBackground(new Color(234, 234, 234));
        walk.setSelected(true);
        startCom.addItem("选择起始位置");
        endCom.addItem("选择终点位置");
        MyJFrame.drawPanel.messageText=messageText;
        for(vexsinfo v:new fileUse().getAllVex().values()){
            startCom.addItem(v.name);
            endCom.addItem(v.name);
        }
        String timeItem[]=MyJFrame.drawPanel.alg.times;
        for(String t:timeItem){
            periodCom.addItem(t);
        }
        startBtn.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                searchNameJFrame searchnamejframe=new searchNameJFrame(getWidth(),0);
                searchnamejframe.addWindowListener(new WindowAdapter() {
                    @Override
                    public void windowClosed(WindowEvent e) {
                        super.windowClosed(e);
                        //起点查找窗口关闭后
                        showStartAndEnd();
                        startCom.setSelectedItem(startName);
                    }
                });
            }
        });
        endBtn.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                searchNameJFrame searchnamejframe=new searchNameJFrame(getWidth(),1);
                searchnamejframe.addWindowListener(new WindowAdapter() {
                    @Override
                    public void windowClosed(WindowEvent e) {
                        super.windowClosed(e);
                        //查找窗口关闭后
                        showStartAndEnd();
                        endCom.setSelectedItem(endName);
                    }
                });
            }
        });
        startCom.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //起点选择发生变化后
                if(startCom.getSelectedItem().toString().equals("选择起始位置")){
                    startName="";
                    showStartAndEnd();
                    return;
                }
                startName=startCom.getSelectedItem().toString();
                MyJFrame.drawPanel.shortest.clear();
                showStartAndEnd();
            }
        });
        endCom.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //终点选择发生变化后
                if(startCom.getSelectedItem().toString().equals("选择终点位置")){
                    endName="";
                    showStartAndEnd();
                    return;
                }
                endName=endCom.getSelectedItem().toString();
                MyJFrame.drawPanel.shortest.clear();
                showStartAndEnd();
            }
        });
        optimalBtn.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                //找出所有抵达的路线并计算时间最少的路线
                if(startCom.getSelectedItem().toString().equals("选择起始位置")||endCom.getSelectedItem().toString().equals("选择终点位置")){
                    JOptionPane.showMessageDialog(null,"请选择起点与终点");
                    return;
                }
                messageText.setText("");
                distanceLabel.setText("");
                warnLabel.setText("");
                List<Integer> list;
                if(!walk.isSelected()) //Floyd弗洛伊德只针对车
                    list=MyJFrame.drawPanel.alg.Floyd(startCom.getSelectedItem().toString(),endCom.getSelectedItem().toString());
                else {
                    list=MyJFrame.drawPanel.alg.Dijkstra(startCom.getSelectedItem().toString(),endCom.getSelectedItem().toString(),"步行");
                }
                int s=MyJFrame.drawPanel.alg.getListIdsDistance(list);
                if(s==65535){
                    JOptionPane.showMessageDialog(null,"无法到达");
                    return;
                }
                int t=walk.isSelected()?s/2:MyJFrame.drawPanel.alg.getTwoPTime(startName,endName);
                distanceLabel.setText(startName+" -> "+endName+": "+s+"m 预计用时："+t+"s");
                String warn=MyJFrame.drawPanel.alg.messageCrowded(list,periodCom.getSelectedItem().toString());  //返回该时间段所经历的节点相关拥挤信息
                warnLabel.setText(warn);
                MyJFrame.drawPanel.towPointDrawLine(list); //list是节点数组，起始到终点姚经历的节点
                MyJFrame.drawPanel.repaint();
            }
        });
        shortestBtn.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                if(startCom.getSelectedItem().toString().equals("选择起始位置")||endCom.getSelectedItem().toString().equals("选择终点位置")){
                    JOptionPane.showMessageDialog(null,"请选择起点与终点");
                    return;
                }
                messageText.setText("");
                distanceLabel.setText("");
                List<Integer> shortestLoads;
                if(walk.isSelected())
                    shortestLoads=MyJFrame.drawPanel.alg.Dijkstra(startCom.getSelectedItem().toString(),endCom.getSelectedItem().toString(),"步行");
                else if(driving.isSelected())
                    shortestLoads=MyJFrame.drawPanel.alg.Dijkstra(startCom.getSelectedItem().toString(),endCom.getSelectedItem().toString(),"驾车");
                else
                    shortestLoads=MyJFrame.drawPanel.alg.Dijkstra(startCom.getSelectedItem().toString(),endCom.getSelectedItem().toString(),"骑行");
                if(shortestLoads==null){
                    JOptionPane.showMessageDialog(null,"无法到达");
                    return; //如果无法到达
                }
                MyJFrame.drawPanel.towPointDrawLine(shortestLoads); //画线
                int s=MyJFrame.drawPanel.alg.getListIdsDistance(shortestLoads);
                String warn=MyJFrame.drawPanel.alg.messageCrowded(shortestLoads,periodCom.getSelectedItem().toString());
                warnLabel.setText(warn);
                String goWay=walk.isSelected()?"步行":driving.isSelected()?"驾车":"骑行";
                int t=MyJFrame.drawPanel.alg.getListTime(shortestLoads,goWay,periodCom.getSelectedItem().toString());
                distanceLabel.setText(startName+" -> "+endName+": "+s +"m 预计用时："+t+"s");
            }
        });
        runStartBtn.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                if(MyJFrame.drawPanel.shortest.isEmpty()){
                    JOptionPane.showMessageDialog(null,"请先选择路线方式(最优或最短)");
                    return;
                }
                Thread t=new Thread((Runnable) MyJFrame.drawPanel);
                t.start();
            }
        });
        speedUpBtn.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                if(MyJFrame.drawPanel.speedUp==3){
                    MyJFrame.drawPanel.speedUp=1;
                    MyJFrame.drawPanel.every=1;
                    speedUpBtn.setText("开始虚拟加速");
                }else {
                    MyJFrame.drawPanel.speedUp=3;
                    MyJFrame.drawPanel.every=1*MyJFrame.drawPanel.speedUp;
                    speedUpBtn.setText("停止虚拟加速");
                }
            }
        });
        driving.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                if(driving.isSelected()){
                    MyJFrame.drawPanel.goWay="驾车";
                }
            }
        });
        cycling.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                if(driving.isSelected()){
                    MyJFrame.drawPanel.goWay="骑行";
                }
            }
        });
        addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                super.windowClosing(e);
                MyJFrame.drawPanel.showPoints.clear();
                MyJFrame.drawPanel.shortest.clear();
                MyJFrame.drawPanel.repaint();
            }
        });
        add(warnLabel);
        add(cycling);
        add(runStartBtn);
        add(speedUpBtn);
        add(messageText);
        add(distanceLabel);
        add(shortestBtn);
        add(optimalBtn);
        add(periodLabel);
        add(periodCom);
        buttonGroup.add(walk);
        buttonGroup.add(cycling);
        buttonGroup.add(driving);
        add(transportWayLabel);
        add(walk);add(driving);
        add(startLabel);
        add(endLabel);
        add(startCom);
        add(endCom);
        add(startBtn);
        add(endBtn);
        setVisible(true);
    }
}
//介绍页面
class introduceJFrame extends JFrame{
    JList nameList=new JList();
    public introduceJFrame(int x){
        setLayout(null);
        setSize(550,600);
        setLocation(x,0);
        SetMyLayout();
        setVisible(true);
    }
    private void SetMyLayout(){
        getContentPane().setLayout(null);
        JTextField inputPosition =new JTextField();
        JButton searchBtn=new JButton("搜索");
        inputPosition.setBounds(20,10,getWidth()-110,30);
        searchBtn.setBounds(getWidth()-80,10,80-20,30);
        getContentPane().add(inputPosition);
        getContentPane().add(searchBtn);
        inputPosition.addFocusListener(new FocusAdapter() {
            @Override
            public void focusGained(FocusEvent e) {
                super.focusGained(e);
                if(inputPosition.getText().equals("请输入你要搜索的地点")){
                    inputPosition.setText("");
                }
            }

            @Override
            public void focusLost(FocusEvent e) {
                super.focusLost(e);
                if(inputPosition.getText().equals("")){
                    inputPosition.setText("请输入你要搜索的地点");
                }
            }
        });

        List<String> names=new fileUse().getNames();
        JScrollPane scrollPane = new JScrollPane();
        scrollPane.setBounds(20,60,this.getWidth()-40,this.getHeight()-110);
        scrollPane.setViewportView(nameList);
        DefaultListModel nameListModel = new DefaultListModel();
        nameList.setModel(nameListModel);
        nameList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);  //单一选择模式
        nameListModel.addAll(names);
        getContentPane().add(scrollPane);

        searchBtn.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                System.out.println("你的选择是"+nameList.getSelectedValue());
            }
        });
        nameList.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                inputPosition.setText(nameList.getSelectedValue().toString());
                vexsinfo v=new fileUse().getVexByName(nameList.getSelectedValue().toString());
                MyJFrame.drawPanel.showPoints.clear();
                MyJFrame.drawPanel.showPoints.put(v.id,v);
                MyJFrame.drawPanel.repaint();
                if(e.getClickCount()==2){ //该查找窗口内双击列表项
                    showPosition(nameList.getSelectedValue().toString());
                }
            }
        });

    }
    private void showPosition(String name){
        vexsinfo v=new vexsinfo();
        for(vexsinfo vex : new fileUse().getAllVex().values()){
            if(name.equals(vex.name)){
                v=vex;
                break;
            }
        }
        JFrame jFrame=new JFrame();
        jFrame.setSize(350,400);
        jFrame.setLayout(null);
        JLabel title=new JLabel(name);
        title.setFont(new Font("黑体",Font.BOLD,12));
        title.setBounds(20,10,290,25);
        jFrame.add(title);
        JTextArea jTextArea=new JTextArea();
        jTextArea.setBounds(20,40,290,330);
        jTextArea.append("*是否可通车:"+(v.drive==1?"通":"不通")+"\n");
        jTextArea.append("*简介:\n");
        jTextArea.append(v.introduction+"\n");
        jFrame.add(jTextArea);
        jFrame.setVisible(true);
    }
}
//搜索页面
class searchNameJFrame extends JFrame{
    vexsinfo clickV=null;
    public searchNameJFrame(int x,int startOrEnd){
        setLayout(null);
        setSize(550,600);
        setLocation(x,0);
        SetMyLayout(startOrEnd);
        setTitle("搜索页");
        setVisible(true);
    }
    private void SetMyLayout(int startOrEnd){
        Container c=this.getContentPane();
        c.setLayout(null);
        JTextField inputPosition =new JTextField();
        JButton searchBtn=new JButton("搜索");
        inputPosition.setBounds(20,10,getWidth()-110,30);
        searchBtn.setBounds(getWidth()-80,10,80-20,30);
        c.add(inputPosition);
        c.add(searchBtn);
        inputPosition.addFocusListener(new FocusAdapter() {
            @Override
            public void focusGained(FocusEvent e) {
                super.focusGained(e);
                if(inputPosition.getText().equals("请输入你要搜索的地点")){
                    inputPosition.setText("");
                }
            }
            @Override
            public void focusLost(FocusEvent e) {
                super.focusLost(e);
                if(inputPosition.getText().equals("")){
                    inputPosition.setText("请输入你要搜索的地点");
                }
            }
        });
        List<String> names=new fileUse().getNames();
        JScrollPane scrollPane = new JScrollPane();
        JList nameList=new JList();
        scrollPane.setBounds(20,60,this.getWidth()-40,this.getHeight()-110);
        scrollPane.setViewportView(nameList);
        DefaultListModel nameListModel = new DefaultListModel();
        nameList.setModel(nameListModel);
        nameList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);  //单一选择模式
        nameListModel.addAll(names);
        c.add(scrollPane);

        searchBtn.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                System.out.println("你的选择是"+nameList.getSelectedValue());
            }
        });
        nameList.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                String selectName=nameList.getSelectedValue().toString();
                inputPosition.setText(selectName);
                vexsinfo v=new fileUse().getVexByName(selectName);
                if(clickV!=null)MyJFrame.drawPanel.showPoints.remove(clickV.id);
                MyJFrame.drawPanel.showPoints.put(v.id,v);
                clickV=v;
                MyJFrame.drawPanel.repaint();
                if(e.getClickCount()==2){
                   if(startOrEnd==0)navigationJFrame.startName=selectName;  //startOrEnd判断打开的搜索框是开始Com还是终点的Com的搜索框
                   else navigationJFrame.endName=selectName;
                   MyJFrame.drawPanel.showPoints.remove(v.id);
                   dispose();
                }
            }
        });

    }
}
